#ifndef __MUSKET_BLOCK_H__
#define __MUSKET_BLOCK_H__

#include "Block.hpp"
#include "Blocks/BulletBlock.h"

namespace PocketSurvival
{

	enum class MusketLoadState
	{
		Empty,
		Gunpowder,
		Wad,
		Loaded
	};

    // 火枪
    class MusketBlock : public Block
    {
    public:
        static constexpr int32_t Index()
        {
            return 212;
        }
        virtual int32_t getIndex() override; 
        virtual const std::string &getBlockName() override;

        virtual int32_t getDamage(int32_t value) override;
        virtual int32_t setDamage(int32_t value, int32_t damage) override;

		static inline MusketLoadState GetLoadState(int32_t data);
		static inline int32_t SetLoadState(int32_t data, MusketLoadState loadState);
		static inline bool GetHammerState(int32_t data);
		static inline int32_t SetHammerState(int32_t data, bool state);
		static inline BulletType GetBulletType(int32_t data);
		static inline int32_t SetBulletType(int32_t data, BulletType bulletType);

    };


	inline MusketLoadState MusketBlock::GetLoadState(int32_t data)
	{
		return (MusketLoadState)(data & 3);
	}

	inline int32_t MusketBlock::SetLoadState(int32_t data, MusketLoadState loadState)
	{
		return (data & -4) | ((int32_t)loadState & (int32_t)MusketLoadState::Loaded);
	}

	inline bool MusketBlock::GetHammerState(int32_t data)
	{
		return (data & 4) != 0;
	}

	inline int32_t MusketBlock::SetHammerState(int32_t data, bool state)
	{
		return (data & -5) | ((state ? 1 : 0) << 2);
	}

	inline BulletType MusketBlock::GetBulletType(int32_t data)
	{
		int32_t num = (data >> 4) & 0xF;
        return (BulletType)num;
	}

	inline int32_t MusketBlock::SetBulletType(int32_t data, BulletType bulletType)
	{
		int32_t num = (int32_t)bulletType;
		return (data & -241) | ((num & 0xF) << 4);
	}

} // namespace PocketSurvival

#endif
